package com.haixiaoke.service.impl;

import java.util.Date;
import java.util.List;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.haixiaoke.common.utils.DateUtils;
import com.haixiaoke.common.utils.StringUtils;
import com.haixiaoke.domain.SmartLock;
import com.haixiaoke.domain.SmartLockBluetooth;
import com.haixiaoke.mapper.SmartLockBluetoothMapper;
import com.haixiaoke.service.ISmartLockBluetoothService;
import com.haixiaoke.smartLock.tianwanghulian.SmartLockTWHlService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 蓝牙授权信息Service业务层处理
 *
 * @author xiaolong
 * @date 2023-05-27
 */
@Service
public class SmartLockBluetoothServiceImpl implements ISmartLockBluetoothService {
    @Autowired
    private SmartLockBluetoothMapper smartLockBluetoothMapper;
    @Autowired
    private SmartLockTWHlService smartLockTWHlService;

    /**
     * 查询蓝牙授权信息
     *
     * @param bluetoothId 蓝牙授权信息主键
     * @return 蓝牙授权信息
     */
    @Override
    public SmartLockBluetooth selectSmartLockBluetoothByBluetoothId(Long bluetoothId) {
        return smartLockBluetoothMapper.selectSmartLockBluetoothByBluetoothId(bluetoothId);
    }

    /**
     * 查询蓝牙授权信息列表
     *
     * @param smartLockBluetooth 蓝牙授权信息
     * @return 蓝牙授权信息
     */
    @Override
    public List<SmartLockBluetooth> selectSmartLockBluetoothList(SmartLockBluetooth smartLockBluetooth) {
        return smartLockBluetoothMapper.selectSmartLockBluetoothList(smartLockBluetooth);
    }

    /**
     * 新增蓝牙授权信息和授权蓝牙开锁
     *
     * @param smartLockBluetooth 蓝牙授权信息
     * @return 结果
     */
    @Override
    public int insertSmartLockBluetooth(SmartLockBluetooth smartLockBluetooth) {
        smartLockBluetooth.setCreateTime(DateUtils.getNowDate());
        return smartLockBluetoothMapper.insertSmartLockBluetooth(smartLockBluetooth);
    }

    /**
     * 修改蓝牙授权信息
     *
     * @param smartLockBluetooth 蓝牙授权信息
     * @return 结果
     */
    @Override
    public int updateSmartLockBluetooth(SmartLockBluetooth smartLockBluetooth) {
        smartLockBluetooth.setUpdateTime(DateUtils.getNowDate());
        return smartLockBluetoothMapper.updateSmartLockBluetooth(smartLockBluetooth);
    }

    /**
     * 批量删除蓝牙授权信息
     *
     * @param bluetoothIds 需要删除的蓝牙授权信息主键
     * @return 结果
     */
    @Override
    public int deleteSmartLockBluetoothByBluetoothIds(Long[] bluetoothIds) {
        return smartLockBluetoothMapper.deleteSmartLockBluetoothByBluetoothIds(bluetoothIds);
    }

    /**
     * 删除蓝牙授权信息信息
     *
     * @param bluetoothId 蓝牙授权信息主键
     * @return 结果
     */
    @Override
    public int deleteSmartLockBluetoothByBluetoothId(Long bluetoothId) {
        return smartLockBluetoothMapper.deleteSmartLockBluetoothByBluetoothId(bluetoothId);
    }

    @Override
    public int deleteSmartLockBluetoothByLockSNAndIdentification(String sn, String identification) {
        return smartLockBluetoothMapper.deleteSmartLockBluetoothByLockSNAndIdentification(sn,identification);
    }

    @Override
    public List<SmartLockBluetooth> selectSmartLockBluetoothBySN(String sn) {
        SmartLockBluetooth smartLockBluetooth = new SmartLockBluetooth();
        smartLockBluetooth.setSn(sn);
        return smartLockBluetoothMapper.selectSmartLockBluetoothList(smartLockBluetooth);
    }

    public int deleteSmartLockBluetoothBySn(String sn) {
        return smartLockBluetoothMapper.deleteSmartLockBluetoothBySn(sn);
    }

    public int deleteSmartLockBluetoothByEndTime(DateTime date) {
        return smartLockBluetoothMapper.deleteSmartLockBluetoothByEndTime(date);
    }

    public int deleteSmartLockBluetoothBySnAndIdentification(String sn, String mobile) {
        return smartLockBluetoothMapper.deleteSmartLockBluetoothBySnAndIdentification(sn, mobile);
    }
}
